<template>
  <section>
    <div class="message-personal-group">
      <el-dialog :visible.sync="personalDialogVisiable" title="推送对象" :close-on-click-modal="false" width="1500px">
        <ue-search-bar :data="querys" ref="ueSearchBar" v-model="searchForm">
        </ue-search-bar>
        <el-button type="primary" @click.native="resetSearchForm" class="mButton mButtonRight">重置</el-button>
        <el-button type="primary" @click.native="searchPersonalGroups" class="mButton mButtonRight">查询</el-button>
        <el-button type="primary" @click.native="reSendAllFail">所有失败重新发送</el-button>
        <el-table :data="tableData" highlight-current-row border max-height="680">
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column prop="mebPersonalDTO.realName" label="客户名称"></el-table-column>
      <el-table-column prop="mebPersonalDTO.phone" label="联系手机"></el-table-column>
      <el-table-column prop="mebPersonalDTO.enterprise" label="企业名称"></el-table-column>
      <el-table-column prop="mebPersonalDTO.createDate" label="注册日期">
        <template slot-scope="scope">
          <label v-if="scope.row.mebPersonalDTO.createDate != null">{{scope.row.mebPersonalDTO.createDate.substring(0,10)}}</label>
        </template></el-table-column>
      <el-table-column prop="mebPersonalDTO.partnerName" label="邀请人"></el-table-column>
      <el-table-column  label="所在城市">
        <template slot-scope="scope">{{scope.row.mebPersonalDTO.province}}{{scope.row.mebPersonalDTO.city}}{{scope.row.mebPersonalDTO.county}}</template>
      </el-table-column>
      <el-table-column  label="推送结果" prop="status">
        <template slot-scope="scope">
          <label v-if="scope.row.status === 'FAIL'" style="color: red">失败</label>
          <label v-else>成功</label>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === 'FAIL'" type="primary" @click.native="reSendMessage(scope.row)">重新发送</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--工具条-->
    <el-row>
      <el-col :span="24" class="toolbar">
        <el-pagination
          :current-page="currentPage"
          :page-size="pageSize"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total,sizes,prev, pager, next, jumper"
          :total="total" style="float: right;">
        </el-pagination>
      </el-col>
    </el-row>
      </el-dialog>
    </div>
  </section>
</template>

<script>
import {resendMessage} from '../../api/v3/Message';
import {getAllMessageMebPersonals} from '../../api/v3/MessageMebPersonal';
export default {
  name: 'message-personal-group',
  componentName: 'message-personal-group',
  data () {
    return {
      personalDialogVisiable: false,
      searchForm: {},
      selectedId: '',
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0
    };
  },
  methods: {
    show (o) {
      if (o) {
        this.selectedId = o.id;
        this.personalDialogVisiable = true;
        getAllMessageMebPersonals({
          filters: 'EQ_message.id=' + o.id,
          page: this.currentPage - 1,
          size: this.pageSize
        }).then((res) => {
          this.tableData = res.data;
          this.total = Number(res.headers['x-total-count']);
        });
      }
    },
    searchPersonalGroups () {
      getAllMessageMebPersonals({
        filters: 'EQ_message.id=' + this.selectedId + ';' + this.$ue.objToFilter(this.searchForm),
        page: this.currentPage - 1,
        size: this.pageSize
      }).then((res) => {
        this.tableData = res.data;
        this.total = Number(res.headers['x-total-count']);
      });
    },
    reSendMessage (o) {
      resendMessage(this.selectedId, o.mebPersonalDTO.id).then((res) => {
        this.$message.success('重新发送成功');
      });
    },
    reSendAllFail () {
      resendMessage(this.selectedId, null).then((res) => {
        this.$message.success('重新发送成功');
      });
    },
    resetSearchForm () {
      this.$refs.ueSearchBar.reset();
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      this.searchPersonalGroups();
    },
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchPersonalGroups();
    }
  },
  computed: {
    btns () {
      return this.$store.state.btns[this.$route.path] || [];
    },
    querys () {
      return this.$store.state.querys['/message/MessageRecord#mebPersonal'] || [];
    }
  },
  // 初始化数据
  mounted () {
    this.$store.commit('initDict');
  }
};
</script>

<style lang="less">
  .message-personal-group {
    .mButton {
      margin-bottom: 10px;
    }

    .mButtonRight {
      float: right;
      margin-right: 10px;
    }
  }
</style>
